//
//  CZDiscoverySearchView.swift
//  WHWeiBo
//
//  Created by Li Changjian on 16/7/12.
//  Copyright © 2016年 Li Changjian. All rights reserved.
//

import UIKit

class CZDiscoverySearchView: UIView ,UITextFieldDelegate{

    @IBOutlet weak var searchTextField: UITextField!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var searchTextFieldTrailingConstraint: NSLayoutConstraint!
    
    class func searchView() -> CZDiscoverySearchView {
        let nib = UINib(nibName: "CZDiscoverySearchView", bundle: nil)
        return (nib.instantiateWithOwner(nil, options: nil).last as? CZDiscoverySearchView)!
    }
    
    
    
    func textFieldDidBeginEditing(textField: UITextField) {
        
        textField.resignFirstResponder()
        
        searchTextFieldTrailingConstraint.constant = cancelButton.width
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    
    
    
    
    
    @IBAction func cancelAction(sender: UIButton) {
        
        searchTextFieldTrailingConstraint.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    
    

}
